﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Waaahsabi.Controls.DWM
{
	public class StartMenuProgramGroupItem : Control
	{
		private Button _btnItemButton;
		public event EventHandler<ProgramItemExecuteArgs> Click;


		public static readonly DependencyProperty InterfaceIdProperty =
		DependencyProperty.Register
			(
			"InterfaceId",
			typeof(ulong),
			typeof(StartMenuProgramGroupItem),
			new PropertyMetadata(null)
			);

		public ulong InterfaceId
		{
			get { return (ulong)GetValue(InterfaceIdProperty); }
			set { SetValue(InterfaceIdProperty, value); }
		}

		public static readonly DependencyProperty ProgramNameProperty =
		DependencyProperty.Register
			(
			"ProgramName",
			typeof(string),
			typeof(StartMenuProgramGroupItem),
			new PropertyMetadata("No Program Name")
			);

		public string ProgramName
		{
			get { return (string)GetValue(ProgramNameProperty); }
			set { SetValue(ProgramNameProperty, value); }
		}

		#region ProgramId DependencyProperty
		public static readonly DependencyProperty ProgramIdProperty =
		DependencyProperty.Register
			(
			"ProgramId",
			typeof(ulong),
			typeof(StartMenuProgramGroupItem),
			new PropertyMetadata(null)
			);

		public ulong ProgramId
		{
			get { return (ulong)GetValue(ProgramIdProperty); }
			set { SetValue(ProgramIdProperty, value); }
		}
		#endregion


		public int ProgramVersion { get; set; }

		public StartMenuProgramGroupItem()
		{
			DefaultStyleKey = typeof(StartMenuProgramGroupItem);
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			_btnItemButton = GetTemplateChild("btnItemButton") as Button;
			if (_btnItemButton != null)
			{
				_btnItemButton.Click += (s, e) =>
				{
					if (Click != null)
						Click(this, new ProgramItemExecuteArgs { InterfaceId = InterfaceId, ProgramVersion = ProgramVersion, ProgramName = ProgramName, ProgramId = ProgramId});
				};
			}
		}
	}

	public class ProgramItemExecuteArgs : EventArgs
	{
		public ulong ProgramId { get; set; }
		public ulong InterfaceId { get; set; }
		public int ProgramVersion { get; set; }
		public string ProgramName { get; set; }
	}
}
